<script type="text/javascript">
    let treetable;
    layui.use(['layer', 'form', 'index', 'table', 'treetable'], function () {
        let layer = layui.layer;
        let form = layui.form;
        let table = layui.table;
        let tree = layui.treetable;
        layer.load(2);
        treetable = tree.render({
            treeColIndex: 0,
            treeSpid: '',
            treeIdName: 'industry_id',
            treePidName: 'parent_id',
            treeDefaultClose: true,
            elem: '#dataTable',
            url: "{{route('admin.base.industry.getAllData')}}",
            cols: [
                [{
                    title: '名称',
                    field: 'name',
                    width: 200
                }, {
                    title: '关键字',
                    field: 'keywords',
                    width: 300
                }, {
                    title: '备注',
                    field: 'description'
                }, {
                    title: '是否有效',
                    field: 'status',
                    width: 100,
                    templet: function (res) {
                        return res.status == 1 ? '是' : '否';
                    }
                }, {
                    title: '操作',
                    fixed: 'right',
                    align: 'center',
                    toolbar: '#options'
                }]
            ],
            done: function () {
                layer.closeAll('loading');
            }
        });

        table.on('tool(dataTable)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;
            switch (layEvent) {
                case 'show':
                    location.href = 'industry/' + data.industry_id + '/false/show';
                    break;
                case 'edit':
                    location.href = 'industry/' + data.industry_id + '/false/edit';
                    break;
                case 'del':
                    layer.confirm('确认删除吗？', function (index) {
                        $.post("{{ route('admin.base.industry.destroy') }}", {
                                '_method': 'delete',
                                '_token': '{{csrf_token()}}',
                                ids: data.industry_id
                            },
                            function (result) {
                                if (result.code == 0) {
                                    obj.del(); //删除对应行（tr）的DOM结构
                                }
                                layer.close(index);
                                layer.msg(result.msg);
                            });
                    });
                    break;
                default:
                    break;
            }
        });
    });

    function search() {
        dataTable.reload({
            where: {
                key: $('#key').val()
            },
            page: {
                curr: 1
            }
        });
    }

</script>
